﻿<?php


class SettingApp extends BaseApp
{
    function index()
    {
		
		$TB_set = &$this->_model('setting'); 	
		$setdata = $TB_set->show();
		$data = array();
		foreach($setdata as $key => $value)
		{
           $data[$value['keyname']] = $value['value'];		   
		}
		
		!isset($data['waterimg_dir'])?$data['waterimg_dir']='':'';
		!isset($data['site_url'])?$data['site_url']='':'';
		!isset($data['site_title'])?$data['site_title']='':'';		
		!isset($data['site_keywords'])?$data['site_keywords']='':'';		
		!isset($data['site_description'])?$data['site_description']='':'';		
		!isset($data['miibeian'])?$data['miibeian']='':'';
		!isset($data['upfile_path'])?$data['upfile_path']='':'';		
		!isset($data['thumb_width'])?$data['thumb_width']='':'';		
		!isset($data['thumb_height'])?$data['thumb_height']='':'';			
		!isset($data['is_waterimg'])?$data['is_waterimg']='':'';
		!isset($data['max_file_size'])?$data['max_file_size']='':'';		
		!isset($data['upfile_types'])?$data['upfile_types']='':'';		
		!isset($data['enabled_gzip'])?$data['enabled_gzip']='':'';			
		!isset($data['system_url_rewrite'])?$data['system_url_rewrite']='':'';		
		!isset($data['version_info'])?$data['version_info']='':'';			
		!isset($data['system_open'])?$data['system_open']='':'';
		!isset($data['system_open_reason'])?$data['system_open_reason']='':'';		
		!isset($data['allow_register'])?$data['allow_register']='':'';		
		!isset($data['close_register_reason'])?$data['close_register_reason']='':'';			
		!isset($data['login_verycode'])?$data['login_verycode']='':'';		
		!isset($data['register_verycode'])?$data['register_verycode']='':'';		
		!isset($data['lang'])?$data['lang']='':'';		
		!isset($data['cookie_domain'])?$data['cookie_domain']='':'';		
		!isset($data['cookie_path'])?$data['cookie_path']='':'';		
		!isset($data['cookie_secure'])?$data['cookie_secure']='':'';		
		!isset($data['cookie_prefix'])?$data['cookie_prefix']='':'';		
		!isset($data['session_prefix'])?$data['session_prefix']='':'';		
		!isset($data['session_max_life_time'])?$data['session_max_life_time']='':'';
		!isset($data['cache_server'])?$data['cache_server']='':'';		
		!isset($data['user_type'])?$data['user_type']='':'';		
		!isset($data['view_type'])?$data['view_type']='':'';		
		!isset($data['css_type'])?$data['css_type']='':'';		
		!isset($data['enabled_subdomain'])?$data['enabled_subdomain']='':'';		
		!isset($data['subdomain_suffix'])?$data['subdomain_suffix']='':'';		
		!isset($data['system_mysql_session'])?$data['system_mysql_session']='':'';		
		!isset($data['encrypt_key'])?$data['encrypt_key']='':'';	
		!isset($data['away_use_keyword'])?$data['away_use_keyword']='':'';		
		!isset($data['away_use_zhandian'])?$data['away_use_zhandian']='':'';			
		!isset($data['qq_set_data'])?$data['qq_set_data']='':'';		
		!isset($data['system_url_rewrite'])?$data['system_url_rewrite']='':'';	
		!isset($data['system_url_html_rewrite'])?$data['system_url_html_rewrite']='':'';
		!isset($data['queuenum'])?$data['queuenum']='':'';			
		
		!isset($data['sms_type'])?$data['sms_type']='':'';	
		!isset($data['sms_es_name'])?$data['sms_es_name']='':'';
		!isset($data['sms_es_key'])?$data['sms_es_key']='':'';		
		!isset($data['sms_wi_id'])?$data['sms_wi_id']='':'';		
		!isset($data['sms_wi_pwd'])?$data['sms_wi_pwd']='':'';
		
 		!isset($data['mail_server'])?$data['mail_server']='':''; 
 		!isset($data['mail_port'])?$data['mail_port']='':'';
		!isset($data['mail_id'])?$data['mail_id']='':'';
		!isset($data['mail_pw'])?$data['mail_pw']='':'';
		
		!isset($data['ini_password'])?$data['ini_password']='phpscup':'';			
		
		!isset($data['session_users_count'])?$data['session_users_count']='':'';
					
		!isset($data['limit_ip_filedir'])?$data['limit_ip_filedir']='':'';
		!isset($data['filter_world_filedir'])?$data['filter_world_filedir']='':'';		
		!isset($data['qian_jifengshu'])?$data['qian_jifengshu']='1':'';		
        $icondataarray = array();
        $temparray = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata');
	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.icon'))
		   {
		    $icondataarray[str_replace('.icon','',$value)] = $value;
		   }
		}
        $this->assign('icondataarray', $icondataarray);

					
        $this->assign('data', $data);		

			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('setting.view.php');
    }

    function set()
    {
	    $data = $_POST['data'];

		if($_FILES['postfile1']['tmp_name'])
	    { 		
	    include(ROOT_PATH.'/lib/upfile.lib.php');	  
		$upfile = new Upfile('setting'); 	  
	    $updata = $upfile->_batch_upfile('setting');
		if(!empty($updata)&&isset($updata[1]['path']))
		{
		   if(defined("WATERIMG_DIR"))
		   {
		       $pic_dir1 = ROOT_PATH . '/' . UPFILE_PATH . '/' . WATERIMG_DIR;
		       if(!is_dir($pic_dir)&&file_exists($pic_dir))
		       {
		            del_file($pic_dir);	
		       }		   
		   }
		   $data['waterimg_dir']=$updata[1]['path'];
		}
        }

		if(!isset($data['register_verycode']))$data['register_verycode']=0;
		if(!isset($data['login_verycode']))$data['login_verycode']=0;

		$TB_set = &$this->_model('setting'); 	
	
		$setdata = $TB_set->show();

		$temp_setdata = array();

		
		foreach($setdata as $key => $value)
		{
           $temp_setdata[$value['keyname']] = $value['value'];		   
		}

		
		foreach($data as $key => $value)
		{
           $temp_setdata[$key] = $value;	   
		}
 
		$TB_set->replace('keyname','value',$temp_setdata);

 		$this->write_config($temp_setdata);
		 
        $this->index();
     
    }

		


    function write_config($data)
    {

		 $str = '';
		 
         foreach ($data as $key => $value)
         {
               if (is_string($value) || is_numeric($value) || is_bool($value) || is_null($value))
               {
                    $str .= "define('".strtoupper($key)."','".$value."');\r\n";

                }
         }
		 		 	    	
		 write_file(ROOT_PATH . '/data/config.inc.php',"<?php\r\n".$str.'?>');

    }


}




?>